const Router = require('koa-router');
const router = new Router();
const {
  pcaC
} = require('china-division');




const Mock = require('mockjs'); //生成模拟数据

router.prefix('/plugin')

router.get('/area/province', (ctx, next) => {
  const data = [];
  const areaData = JSON.parse(JSON.stringify(pcaC));
  for (let item of areaData) {
    delete item.children;
    data.push(item);
  }
  ctx.body = tools.stateJson(data);
});

router.get('/area/city', (ctx, next) => {
  const param = ctx.query;
  const data = [];
  const areaData = JSON.parse(JSON.stringify(pcaC));
  for (let item of areaData) {
    if (item.code === param.province) {
      for (let i of item.children) {
        delete i.children;
        data.push(i);
      }
      break;
    }
  }
  ctx.body = tools.stateJson(data);
});

router.get('/area/county', (ctx, next) => {
  const param = ctx.query;
  let data = [];
  const areaData = JSON.parse(JSON.stringify(pcaC));

  for (let item of areaData) {
    for (let i of item.children) {
      if (i.code == param.city) {
        data = i.children;
        break;
      }
    }
  }
  ctx.body = tools.stateJson(data);
});


router.post('/upload', (ctx, next) => {
  let data = {
    key: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg'
  };
  ctx.body = (data);
});


router.get('/upload/qiniuToken', (ctx, next) => {
  let data = {

  };
  ctx.body = tools.stateJson(data);
});



module.exports = router;